<?php

namespace app\admin\traits;

use app\admin\common\Constants;
use think\Config;
use think\Exception;
use think\View;

trait SelectCompany
{

    /**
     * 是否需要动态渲染
     * @param bool $shouldMust
     * @throws Exception
     */
    protected function __companyComponent__($forceShould = true)
    {
        $parentClassName = get_parent_class();
        if ($parentClassName != 'think\Controller') {
            throw new Exception('This trait must be used in Controller ');
        }
        $view = new View();
        $view = View::instance(Config::get('template'), Config::get('view_replace_str'));
        $selected_company = session(Constants::$COMPANY_ID_KEY);
        $view->assign('__MUST_SHOW_SELECT_COMPANY__', is_null($selected_company)&&$forceShould);
        $view->assign('__COMPANY_ID__', $selected_company);
    }

}